<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"
    />
    <title>策略模式-javascript方式</title>
</head>

<body>
    <strong>策略模式的定义是：定义一系列的算法，把它们一个个封装起来，并且使它们可以相互替换。</strong>

    <script type="text/javascript">

        var performance = {
            'S': function (salary) {
                return salary * 4
            },
            'A': function (salary) {
                return salary * 3
            },
            'B': function (salary) {
                return salary * 2
            },
            'SS': function (salary) {
                return salary * 5
            }
        }
        var calculateBonus = function(level, salary){
            return performance[level](salary)
        }

        console.log(calculateBonus('S', 4000))
        console.log(calculateBonus('SS', 2000))

    </script>

</body>

</html>